package com.example.zhoutao.puzzle.History;

import java.util.ArrayList;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zhoutao.puzzle.R;

/**
 * @Author ZT on 2019.4.22
 * @Descripition 自定义一个适配器（把适配器装到ListVIew的工具）
 */

public class MyListViewAdapter extends BaseAdapter {

    ArrayList<HistoryListView>listData;

    LayoutInflater inflater;

    FragmentActivity activity;

    public MyListViewAdapter(FragmentActivity fragmentActivity, ArrayList<HistoryListView>listData) {
        // TODO Auto-generated constructor stub
        this.listData = listData;
        this.activity = fragmentActivity;
        inflater = (LayoutInflater) fragmentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listData.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return listData.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int arg0, View view, ViewGroup arg2) {
        // TODO Auto-generated method stub
        ViewHolder viewHolder=null;

        if (view == null) {
            view = inflater.inflate(R.layout.history_item, null);
            viewHolder=new ViewHolder();
            viewHolder.im=view.findViewById(R.id.iv_headPortrait);
            viewHolder.tv_step=view.findViewById(R.id.tv_step);
            viewHolder.tv_date=view.findViewById(R.id.tv_date);
            viewHolder.tv_time=view.findViewById(R.id.tv_time);
            viewHolder.tv_mode=view.findViewById(R.id.tv_mode);
            view.setTag(viewHolder);
        }
        viewHolder=(ViewHolder)view.getTag();
        HistoryListView model=listData.get(arg0);
        viewHolder.tv_step.setText(model.getStep());
        viewHolder.tv_date.setText(model.getDate());
        viewHolder.tv_time.setText(model.getTime());
        viewHolder.tv_mode.setText(model.getMode());
        viewHolder.im.setImageBitmap(model.getBitmap());


        return view;
    }

    class ViewHolder {
        TextView tv_step;
        TextView tv_date;
        TextView tv_time;
        TextView tv_mode;
        ImageView im;
    }

}

